package net.mingsoft.basic.util;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 * @author gengfa
 * @date 22/06/08
 */
public class GenericSuperclassUtil {
    private GenericSuperclassUtil() {}
    public static Class<?> getActualTypeArgument(Class<?> clazz) {
        Class<?> entityClass = null;
        Type genericSuperclass = clazz.getGenericSuperclass();
        if (genericSuperclass instanceof ParameterizedType) {
            Type[] actualTypeArguments = ((ParameterizedType) genericSuperclass)
                    .getActualTypeArguments();
            if (actualTypeArguments != null && actualTypeArguments.length > 0) {
                entityClass = (Class<?>) actualTypeArguments[0];
            }
        }
        return entityClass;
    }
}
